﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CSharpReview
{

    //   定义一个学生类，存放学生的学号、姓名、性别、年龄、专业信息；
    //   对年龄字段进行赋值的安全性设置，如果是非法值（小于0或者大于128岁），该年龄值为0；
    //   在学生类中定义一个方法输出学生信息。
    class Students
    {
        private int id;
        private string name;
        private string gender;
        private int age;
        private string major;

        public int Id { get => id; set => id = value; }
        public string Name { get => name; set => name = value; }
        public string Gender { get => gender; set => gender = value; }
        public int Age
        {
            get => this.age;
            set 
            {
                if (value >= 0 & value <= 128)
                {
                    this.age = Age;
                }
                else
                {
                    this.age = 0;
                }
            }
        }
        public string Major { get => major; set => major = value; }

        public void PrintStudentInfo()
        {
            Console.WriteLine($"学号：{this.id}，学生姓名:{this.name},性别：{this.gender},年龄：{this.age},专业：{this.major}\n");
        }
    }
}
